package com.xbongbong.pro.enums.smartsettings.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.constant.AiAssistantConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.business.PaymentEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.business.ProductionOrderEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

/**
 * @description: 智能助手特殊字段枚举
 * @Author: hongxiao
 * @date: 2019-04-27 16:18
 * @since v1.0
 */
@Getter
public enum  SmartSettingsFieldEnum {
    // 枚举
    /**
     * 未跟进（客户/供应商）、遗忘（客户/机会/供应商）、待字辈（采购/生产/入库/出库）、访客计划执行人、产品（库存预警/过期预警）、回款（到期/逾期）、付款（到期/逾期）
     */
    NO_CONNECT_CUSTOMER(340101, "noConnectCustomer", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "enum.smartSettingsField.description.no_connect_customer", AiAssistantConstant.NO_CONNNECT, CustomerManagementEnum.LAST_CONNECT_TIME.getAttr(), 1, 1),

    FORGET_CUSTOMER(340102, "forgetCustomer", XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "enum.smartSettingsField.description.forget_customer", AiAssistantConstant.FORGET, CustomerManagementEnum.LAST_CONNECT_TIME.getAttr(), 1, 1),
    // 暂时未使用 2019-05-09 by hongxiao.liu
    NO_CONNECT_OPPORTUNITY(340103, "noConnectOpportunity", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "enum.smartSettingsField.description.no_connect_opportunity", AiAssistantConstant.NO_CONNNECT, SalesOpportunityEnum.LAST_CONNECT_TIME.getAttr(), 1, 1),

    FORGET_OPPORTUNITY(340104, "forgetOpprotunity", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "enum.smartSettingsField.description.forget_opportunity", AiAssistantConstant.FORGET, SalesOpportunityEnum.LAST_CONNECT_TIME.getAttr(), 1, 1),

    NO_CONNECT_SUPPLIER(340105, "noConnectSupplier", XbbRefTypeEnum.SUPPLIER.getCode(), "enum.smartSettingsField.description.no_connect_supplier", AiAssistantConstant.NO_CONNNECT, SupplierEnum.LAST_CONNECT_TIME.getAttr(), 1, 1),

    FORGET_SUPPLIER(340106, "forgetSupplier", XbbRefTypeEnum.SUPPLIER.getCode(), "enum.smartSettingsField.description.forget_supplier", AiAssistantConstant.FORGET, SupplierEnum.LAST_CONNECT_TIME.getAttr(), 1, 1),

    WAIT_PURCHASE(340107, "waitPurchase", XbbRefTypeEnum.CONTRACT.getCode(), "enum.smartSettingsField.description.wait_purchase", AiAssistantConstant.WAIT_FOR_TREAT, "", 1, 1),

    WAIT_PRODUCTION_ORDER(340108, "waitProductionOrder", XbbRefTypeEnum.CONTRACT.getCode(), "enum.smartSettingsField.description.wait_production_order", AiAssistantConstant.WAIT_FOR_TREAT, "", 1, 1),

    WAIT_INSTOCK(340109, "waitInstock", XbbRefTypeEnum.PURCHASE.getCode(), "enum.smartSettingsField.description.wait_instock", AiAssistantConstant.WAIT_FOR_TREAT, "", 1, 1),

    WAIT_OUTSTOCK(340110, "waitOutstock", XbbRefTypeEnum.CONTRACT.getCode(), "enum.smartSettingsField.description.wait_outstock", AiAssistantConstant.WAIT_FOR_TREAT, "", 1, 1),
    // 暂时不支持 2019-05-09 by hongxiao.liu
    COMMUNICATE_PLAN_EXECUTOR(340111, "communicatePlanExecutor", XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), "enum.smartSettingsField.description.communicate_plan_executor", AiAssistantConstant.EXECUTOR, "", 1, 1),
    // 产品预警
    PRODUCT_STOCK_LOWER_WARNING(340112, "productStockLowerWarning", XbbRefTypeEnum.PRODUCT.getCode(), "enum.smartSettingsField.description.product_stock_lower_warning", AiAssistantConstant.STOCK_WARNING, ProductEnum.STOCK_LOWER_LIMIT.getAttr(),1, 1),

    PRODUCT_STOCK_UPPER_WARNING(340113, "productStockUpperWarning", XbbRefTypeEnum.PRODUCT.getCode(), "enum.smartSettingsField.description.product_stock_upper_warning", AiAssistantConstant.STOCK_WARNING, ProductEnum.STOCK_UPPER_LIMIT.getAttr(),1, 1),

    PRODUCT_EXPIRE_WARNING(340114, "productExpireWarning", XbbRefTypeEnum.PRODUCT.getCode(), "enum.smartSettingsField.description.product_expire_warning", AiAssistantConstant.EXPIRE_WARNING, "", 1, 1),
    // 合同到期筛选条件（当天，之前）
    CONTRACT_DEAD_LINE(340115, "contractDeadLine", XbbRefTypeEnum.CONTRACT.getCode(), "enum.smartSettingsField.description.contract_dead_line", ContractEnum.DEADLINE.getSaasAttr(), ContractEnum.DEADLINE.getAttr(), 1, 1),
    // 销售阶段变更提醒，筛选条件（等于）
    OPPORTUNITY_STAGE(340116, "opportunityStage", XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "enum.smartSettingsField.description.opportunity_stage", SalesOpportunityEnum.SALE_STAGE.getSaasAttr(),SalesOpportunityEnum.SALE_STAGE.getAttr(),  1, 1),
    // 采购到货筛选条件（当天，之前）
    PURCHASE_ARRIVE_TIME(340117, "purchaseArriveTime", XbbRefTypeEnum.PURCHASE.getCode(), "enum.smartSettingsField.description.purchase_arrive_time", PurchaseEnum.ESTIMATE_ARRIVE_TIME.getSaasAttr(), PurchaseEnum.ESTIMATE_ARRIVE_TIME.getAttr(), 1, 1),
    // 生产完成筛选条件（当天，之前）
    PRODUCTION_ORDER_PLAN_TIME(340118, "productionOrderPlanTime", XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), "enum.smartSettingsField.description.production_order_plan_time", ProductionOrderEnum.PLAN_TIME.getSaasAttr(), ProductionOrderEnum.PLAN_TIME.getAttr(), 1, 1),
    // 回款（到期/逾期）、付款（到期/逾期）
    PAYMENT_DEAD_LINE(340119, "paymentDeadLine", XbbRefTypeEnum.PAYMENT.getCode(), "enum.smartSettingsField.description.payment_dead_line", PaymentEnum.ESTIMATE_TIME.getSaasAttr(), PaymentEnum.ESTIMATE_TIME.getAttr(), 1, 1),

    PAYMENT_OVERDUE(340120, "paymentOverdue", XbbRefTypeEnum.PAYMENT.getCode(), "enum.smartSettingsField.description.payment_overdue", PaymentEnum.ESTIMATE_TIME.getSaasAttr(), PaymentEnum.ESTIMATE_TIME.getAttr(), 1, 1),

    PAY_PLAN_DEAD_LINE(340121, "payPlanDeadLine", XbbRefTypeEnum.PAY_PLAN.getCode(), "enum.smartSettingsField.description.pay_plan_dead_line", PayPlanEnum.ESTIMATE_TIME.getSaasAttr(), PayPlanEnum.ESTIMATE_TIME.getAttr(), 1, 1),

    PAY_PLAN_OVERDUE(340122, "payPlanOverdue", XbbRefTypeEnum.PAY_PLAN.getCode(), "enum.smartSettingsField.description.pay_plan_overdue", PayPlanEnum.ESTIMATE_TIME.getSaasAttr(), PayPlanEnum.ESTIMATE_TIME.getAttr(), 1, 1),

    ;

    /**
     * 字段类型
     */
    private Integer type;

    /**
     * 字段类型英文，ConditionServiceImpl#list用于反射查找对应的字段类型
     */
    private String alias;

    /**
     * saas业务类型
     */
    private Integer businessType;

    /**
     * 字段描述
     */
    private String description;

    /**
     * 类型别名
     */
    private String typeAlias;
    /**
     * form表单字段attr
     */
    private String attr;
    /**
     * 索引最小值
     */
    private Integer min;

    /**
     * 索引最大值
     */
    private Integer max;

    SmartSettingsFieldEnum(Integer type, String alias, Integer businessType, String description, String typeAlias, String attr, Integer min, Integer max) {
        this.type = type;
        this.alias = alias;
        this.businessType = businessType;
        this.description = description;
        this.typeAlias = typeAlias;
        this.attr = attr;
        this.min = min;
        this.max = max;
    }

    public static SmartSettingsFieldEnum getFieldTypeEnum(Integer type) {
        for (SmartSettingsFieldEnum e : values()) {
            if (e.getType().equals(type)) {
                return e;
            }
        }
        return null;
    }

    public static List<String> getAllAlias() {
        List<String> list = new ArrayList<>();
        for (SmartSettingsFieldEnum e : values()) {
            list.add(e.alias);
        }
        return list;
    }

    /**
     * 获取对应的表单字段attr
     * @param alias 别名
     * @return
     * @throws
     * @author hongxiao
     * @date 2019-05-29 15:17
     * @since v1.0
     * @version v1.0
     */
    public static String getFormAttr(String alias) {
        for(SmartSettingsFieldEnum fieldEnum : values()) {
            if(fieldEnum.getAlias().equals(alias)) {
                return fieldEnum.getAttr();
            }
        }
        return null;
    }

    /**
     * 获取表单字段attr对应用的alias
     * @param attr 表单字段attr
     * @param businessType 业务类型
     * @return
     * @throws
     * @author hongxiao
     * @date 2019-05-29 17:12
     * @since v1.0
     * @version v1.0
     */
    public static List<String> getAliasByFormAttr(String attr, Integer businessType) {
        List<String> list = new ArrayList<>();
        for(SmartSettingsFieldEnum fieldEnum : values()) {
            if(fieldEnum.getAttr().equals(attr) && fieldEnum.getBusinessType().equals(businessType)) {
                list.add(fieldEnum.getAlias());
            }
        }
        return list;
    }

    public static List<SmartSettingsFieldEnum> getByFromAttr(String attr, Integer businessType) {
        List<SmartSettingsFieldEnum> list = new ArrayList<>();
        for(SmartSettingsFieldEnum fieldEnum : values()) {
            if(fieldEnum.getAttr().equals(attr) && fieldEnum.getBusinessType().equals(businessType)) {
                list.add(fieldEnum);
            }
        }
        return list;
    }

    public String getDescription() {
        return I18nMessageUtil.getMessage(description);
    }
}
